﻿// escape_time_worker.js

function escapeTime(c, maxiter) {
  var time = 0;

  var x = y = 0;
  while(time < maxiter && x * x + y * y < 4) {
    var newx = x * x - y * y + c[0];
    y = 2 * x * y + c[1];
    x = newx;
    time++;
  }

  if(time < maxiter)
    return 1 - time / maxiter;
  else
    return 0;
}

onmessage = function(evt) {
  postMessage(escapeTime(evt.data, 1000));
}
